//
//  DestinationDetailTableViewController.m
//  TeamProject_Travel
//
//  Created by lanou3g on 16/3/26.
//  Copyright © 2016年 lanou3g. All rights reserved.
//

#import "DestinationDetailTableViewController.h"
#import "DestinationDetailTableViewCell.h"
#import "UIImageView+WebCache.h"
@interface DestinationDetailTableViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
@property(nonatomic,strong)NSMutableArray * allDataArray;
@property(nonatomic,strong)NSMutableArray * noteArray;
@property(nonatomic,strong)NSMutableArray * rowArray;
@end
#define url @"https://chanyouji.com/api/attractions/27394.json?page=1"
@implementation DestinationDetailTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    /*
     
     景点详情界面
     
     */
    [self.tableView registerClass:[DestinationDetailTableViewCell class] forCellReuseIdentifier:@"destinationDetail"];
    
    self.allDataArray = [NSMutableArray array];
    
    [self.allDataArray addObjectsFromArray:self.desModel.attraction_trip_tags];
   

    [self.tableView reloadData];
   
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if (self.allDataArray.count > 0) {
        return self.allDataArray.count;
    }else{
        return 1;
    }
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    self.rowArray = [NSMutableArray array];;
    if (self.allDataArray.count > 0) {
        [self.rowArray addObjectsFromArray:self.desModel.attraction_trip_tags[section][@"attraction_contents"]];
        }

    for (int i = 0; i < self.rowArray.count; i++) {
//        NSLog(@"%@",self.rowArray[i][@"description"]);
    }
//    NSLog(@"===============%ld",section);
    return self.rowArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 40;
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
    NSString *string;
    if (self.allDataArray.count > 0) {
       string = self.allDataArray[section][@"name"];
    }else{
        string = @"";
    }
   
    return string;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    DestinationDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"destinationDetail" forIndexPath:indexPath];
    if (cell == nil) {
        cell = [[DestinationDetailTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"destinationDetail"];
    }
//    NSLog(@"###%ld,,,****%ld",indexPath.section,indexPath.row);
    if (self.allDataArray.count > 0) {
        
        if (indexPath.row < self.rowArray.count) {
            cell.titleLabel.text = self.rowArray[indexPath.row][@"description"];
        }
    }
    
    return cell;
}



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 260;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"image" forIndexPath:indexPath];
    return cell;
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 3;
}



/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
